// 封装接口
import api from './request' //引入封装好的axios

export function getLogin(form) { //登陆接口
    return api.post('/login', form)
}
export function getUserlist(page) { //用户数据
    return api.get(`/users?query=${page.query}&pagenum=${page.pagenum}&pagesize=${page.pagesize}`)
}
export function getStatus(uid, type) {//修改用户状态
    return api.put(`users/${uid}/state/${type}`)
}
export function getAdd(obj) { //添加用户
    return api.post('users', obj)
}
export function getDel(id) { //删除用户
    return api.delete(`users/${id}`)
}
export function getEdit(formedit) { //编辑用户
    let { email, mobile } = formedit
    return api.put(`users/${formedit.id}`, { email, mobile })
}

// 权限管理
export function getRolislist() { //角色列表
    return api.get('roles')
}
export function getrights(tree){ //分配权限列表
    return api.get(`rights/${tree}`)
}
export function getRoles(pramise){ //角色授权
    return api.post(`roles/${pramise.roleld}/rights`,{rids:pramise.rids})
}
export function getAddRolis(ruleForm){ //添加角色
    return api.post('roles',ruleForm)
}
export function getDelRolis(id){ //删除角色
    return api.delete(`roles/${id}`)
}
export function getEditRolis(ruleFormedit,editid){ //编辑角色
    let {roleName,roleDesc} =ruleFormedit
    return api.put(`roles/${editid}`,{roleName,roleDesc})
}
export function getDelroles(roleld,rightID){ //删除角色指定权限
    return api.delete(`roles/${roleld}/rights/${rightID}`)
}
export function getlist(){ //权限列表
    return api.get("rights/list")
}


// 商品管理
export function getCategories(page){ //商品分类
    return api.get(`categories?pagesize=${page.pagesize}&pagenum=${page.pagenum}`)
}
export function getaddCategories(obj){ //添加分类
    let {cat_pid,cat_name,cat_level} = obj
    return api.post('categories',{cat_pid,cat_name,cat_level})
}
export function geteditcategories(pramise){ //编辑提交类
    return api.put(`categories/${pramise.id}`,pramise)
}
export function getdelcategories(id){ //删除分类
    return api.delete(`categories/${id}`)
}
export function getCategorise(obj){ //添加动态或者静态属性
    let {id,attr_name,attr_sel}=obj
    return api.post(`categories/${id}/attributes`,{attr_name,attr_sel})
}
export function getCategorieslist(pramise){ //参数列表
    return api.get(`categories/${pramise.id}/attributes`,{params:{sel:pramise.sel}})
}
export function geteditcategoriesattr(obj){ //编辑提交参数
    return  api.put(`categories/${obj.id}/attributes/${obj.attrId}`,obj)
}
export function getCategoriesdel(obj){ //删除参数
    return api.delete(`categories/${obj.id}/attributes/${obj.attr_id}`,obj)
}
export function getGoodslist(page){ //商品列表数据
    let {pagenum,pagesize} =page
    return api.get('goods',{params:{pagenum,pagesize}})
}
